import {take,call,put,fork} from 'redux-saga/effects';

import {sagGetThirdUserInfo,sagGetUserInfo} from '../../../../../services/pc/member/personal';
//获取user信息
function *sagaGetUserInfo(){
    while (true){
        let action = yield take('GETUSERINFO');
        let payload = yield call(sagGetUserInfo,action.data.data.uId);
        let data = {}
        if (payload.code === 200){
            data.uid=payload.data.uid;
            data.useName=payload.data.nickname;
            data.useEmail='payload.email';
            data.useHeadImg=payload.data.head;
            data.useRole=payload.data.utype;
        }
        yield put({type:'getuserinfo',data})
        if (action.data.success){
            action.data.success(payload)
        }
    }
};
//获取第三方use信息
function *sagaGetThirdUseINfo(){
    while (true){
        let action = yield take('GETTHIRDUSEINFO');
        let payload = yield call(sagGetThirdUserInfo,action.data.data.access_token);
        let data={}
        if (payload){
            data.useId=payload.id;
            data.useName=payload.name;
            data.useEmail=payload.email;
            data.useHeadImg=payload.avatar_url;
            data.useRole=payload.type;
        }
        yield put({type:'getthirduseinfo',data})
        if (action.data.success){
            action.data.success(data)
        }
    }
}

let  aFork=[
    fork(sagaGetThirdUseINfo),
    fork(sagaGetUserInfo)
];
export default aFork;